
#include "IGlobal.h"
#include "member_BEventFilter.h"

using namespace BWE;

member_BEventFilter::member_BEventFilter(BEventFilter* eventFilter)
{
	boss = eventFilter;
	host = 0;
	parent = 0;
}
member_BEventFilter::~member_BEventFilter()
{

}

void member_BEventFilter::setWidget(BWidget* newWidget)
{
	if (host != newWidget)
	{
		if (host)
		{
			boss->detached(host);
			boss->emit(Signal_Detached, BValue(newWidget, true));
		}
		host = newWidget;
		if (host)
		{
			boss->attached(newWidget);
			boss->emit(Signal_Attached, BValue(newWidget, true));
		}
		for (int i = 0; i < children.size(); i++)
		{
			BEventFilter* child = children[i];
			filter_member(child)->setWidget(host);
		}
	}
}
void member_BEventFilter::dispenseEvent(const BEvent& event)
{
	for (int i = 0; i < children.size(); i++)
	{
		BEventFilter* child = children[i];
		if (!child)
			continue;
		filter_member(child)->dispenseEvent(event);
		if (event.accepted())
			return;
	}
	boss->event(event);
}
